<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Getopt::Long - Extended processing of command line options - Perldoc Browser</title>
    <link rel="search" href="https://perldoc.perl.org/opensearch.xml" type="application/opensearchdescription+xml" title="Perldoc Browser">
    <link rel="canonical" href="https://perldoc.perl.org/Getopt::Long">
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" integrity="sha384-JcKb8q3iqJ61gNV9KGb8thSsNjpSL0n8PARn9HuZOnIxN0hoP+VmmDGMN5t9UJ0Z" crossorigin="anonymous">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.5.0/styles/stackoverflow-light.min.css" integrity="sha512-cG1IdFxqipi3gqLmksLtuk13C+hBa57a6zpWxMeoY3Q9O6ooFxq50DayCdm0QrDgZjMUn23z/0PMZlgft7Yp5Q==" crossorigin="anonymous" />
    <style>
      body {
        background: #f4f4f5;
        color: #020202;
      }
      .navbar-dark {
        background-image: -webkit-linear-gradient(top, #005f85 0, #002e49 100%);
        background-image: -o-linear-gradient(top, #005f85 0, #002e49 100%);
        background-image: linear-gradient(to bottom, #005f85 0, #002e49 100%);
        filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff005f85', endColorstr='#ff002e49', GradientType=0);
        background-repeat: repeat-x;
      }
      .navbar-dark .navbar-nav .nav-link,
      .navbar-dark .navbar-nav .nav-link:focus { color: #fff }
      .navbar-dark .navbar-nav .nav-link:hover { color: #ffef68 }
      #wrapperlicious {
        margin: 0 auto;
        font: 0.9em 'Helvetica Neue', Helvetica, sans-serif;
        font-weight: normal;
        line-height: 1.5em;
        margin: 0;
        padding: 0;
      }
      #wrapperlicious h1 { font-size: 1.5em }
      #wrapperlicious h2 { font-size: 1.3em }
      #wrapperlicious h3 { font-size: 1.1em }
      #wrapperlicious h4 { font-size: 0.9em }
      #wrapperlicious h1, #wrapperlicious h2, #wrapperlicious h3,
      #wrapperlicious h4, #wrapperlicious dt {
        color: #020202;
        margin-top: 1em;
        margin-bottom: 1em;
        position: relative;
        font-weight: bold;
      }
      #wrapperlicious a { color: inherit; text-decoration: underline }
      #wrapperlicious #toc { text-decoration: none }
      #wrapperlicious a:hover { color: #2a2a2a }
      #wrapperlicious a img { border: 0 }
      #wrapperlicious :not(pre) > code {
        color: inherit;
        background-color: rgba(0, 0, 0, 0.04);
        border-radius: 3px;
        font: 0.9em Consolas, Menlo, Monaco, monospace;
        padding: 0.3em;
      }
      #wrapperlicious dd {
        margin: 0;
        margin-left: 2em;
      }
      #wrapperlicious dt {
        color: #2a2a2a;
        font-weight: bold;
        margin-left: 0.9em;
      }
      #wrapperlicious p {
        margin-bottom: 1em;
        margin-top: 1em;
      }
      #wrapperlicious li > p {
        margin-bottom: 0;
        margin-top: 0;
      }
      #wrapperlicious pre {
        border: 1px solid #c1c1c1;
        border-radius: 3px;
        font: 100% Consolas, Menlo, Monaco, monospace;
        margin-bottom: 1em;
        margin-top: 1em;
      }
      #wrapperlicious pre > code {
        display: block;
        background-color: #f6f6f6;
        font: 0.9em Consolas, Menlo, Monaco, monospace;
        line-height: 1.5em;
        text-align: left;
        white-space: pre;
        padding: 1em;
      }
      #wrapperlicious dl, #wrapperlicious ol, #wrapperlicious ul {
        margin-bottom: 1em;
        margin-top: 1em;
      }
      #wrapperlicious ul {
        list-style-type: square;
      }
      #wrapperlicious ul ul {
        margin-bottom: 0px;
        margin-top: 0px;
      }
      #footer {
        font-size: 0.8em;
        padding-top: 0.5em;
        text-align: center;
      }
      #more {
        display: inline;
        font-size: 0.8em;
      }
      #perldocdiv {
        background-color: #fff;
        border: 1px solid #c1c1c1;
        border-bottom-left-radius: 5px;
        border-bottom-right-radius: 5px;
        margin-left: auto;
        margin-right: auto;
        padding: 3em;
        padding-top: 1em;
        max-width: 960px;
      }
      #moduleversion { float: right }
      #wrapperlicious .leading-notice {
        font-style: italic;
        padding-left: 1em;
        margin-top: 1em;
        margin-bottom: 1em;
      }
      #wrapperlicious .permalink {
        display: none;
        left: -0.75em;
        position: absolute;
        padding-right: 0.25em;
        text-decoration: none;
      }
      #wrapperlicious h1:hover .permalink, #wrapperlicious h2:hover .permalink,
      #wrapperlicious h3:hover .permalink, #wrapperlicious h4:hover .permalink,
      #wrapperlicious dt:hover .permalink {
        display: block;
      }
    </style>
    <!-- Global site tag (gtag.js) - Google Analytics -->
    <script async src="https://www.googletagmanager.com/gtag/js?id=G-KVNWBNT5FB"></script>
    <script>
      window.dataLayer = window.dataLayer || [];
      function gtag(){dataLayer.push(arguments);}
      gtag('js', new Date());

      gtag('config', 'G-KVNWBNT5FB');
      gtag('config', 'UA-50555-3');
    </script>
  </head>
  <body>
    <nav class="navbar navbar-expand-md navbar-dark bg-dark justify-content-between">
  <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
    <span class="navbar-toggler-icon"></span>
  </button>
  <a class="navbar-brand" href="https://perldoc.perl.org/">Perldoc Browser</a>
  <div class="collapse navbar-collapse" id="navbarNav">
    <ul class="navbar-nav mr-auto">
      <li class="nav-item dropdown text-nowrap">
        <a class="nav-link dropdown-toggle" href="./Getopt::Long.html#" id="dropdownlink-stable" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">5.35.0</a>
        <div class="dropdown-menu" aria-labelledby="dropdownlink-stable">
          <a class="dropdown-item" href="https://perldoc.perl.org/Getopt::Long">Latest</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.38.2/Getopt::Long">5.38.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.38.1/Getopt::Long">5.38.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.38.0/Getopt::Long">5.38.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.36.3/Getopt::Long">5.36.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.36.2/Getopt::Long">5.36.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.36.1/Getopt::Long">5.36.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.36.0/Getopt::Long">5.36.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.34.3/Getopt::Long">5.34.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.34.2/Getopt::Long">5.34.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.34.1/Getopt::Long">5.34.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.34.0/Getopt::Long">5.34.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.32.1/Getopt::Long">5.32.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.32.0/Getopt::Long">5.32.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.30.3/Getopt::Long">5.30.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.30.2/Getopt::Long">5.30.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.30.1/Getopt::Long">5.30.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.30.0/Getopt::Long">5.30.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.28.3/Getopt::Long">5.28.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.28.2/Getopt::Long">5.28.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.28.1/Getopt::Long">5.28.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.28.0/Getopt::Long">5.28.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.26.3/Getopt::Long">5.26.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.26.2/Getopt::Long">5.26.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.26.1/Getopt::Long">5.26.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.26.0/Getopt::Long">5.26.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.24.4/Getopt::Long">5.24.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.24.3/Getopt::Long">5.24.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.24.2/Getopt::Long">5.24.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.24.1/Getopt::Long">5.24.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.24.0/Getopt::Long">5.24.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.22.4/Getopt::Long">5.22.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.22.3/Getopt::Long">5.22.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.22.2/Getopt::Long">5.22.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.22.1/Getopt::Long">5.22.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.22.0/Getopt::Long">5.22.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.20.3/Getopt::Long">5.20.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.20.2/Getopt::Long">5.20.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.20.1/Getopt::Long">5.20.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.20.0/Getopt::Long">5.20.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.18.4/Getopt::Long">5.18.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.18.3/Getopt::Long">5.18.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.18.2/Getopt::Long">5.18.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.18.1/Getopt::Long">5.18.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.18.0/Getopt::Long">5.18.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.16.3/Getopt::Long">5.16.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.16.2/Getopt::Long">5.16.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.16.1/Getopt::Long">5.16.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.16.0/Getopt::Long">5.16.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.14.4/Getopt::Long">5.14.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.14.3/Getopt::Long">5.14.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.14.2/Getopt::Long">5.14.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.14.1/Getopt::Long">5.14.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.14.0/Getopt::Long">5.14.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.12.5/Getopt::Long">5.12.5</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.12.4/Getopt::Long">5.12.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.12.3/Getopt::Long">5.12.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.12.2/Getopt::Long">5.12.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.12.1/Getopt::Long">5.12.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.12.0/Getopt::Long">5.12.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.10.1/Getopt::Long">5.10.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.10.0/Getopt::Long">5.10.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.9/Getopt::Long">5.8.9</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.8/Getopt::Long">5.8.8</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.7/Getopt::Long">5.8.7</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.6/Getopt::Long">5.8.6</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.5/Getopt::Long">5.8.5</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.4/Getopt::Long">5.8.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.3/Getopt::Long">5.8.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.2/Getopt::Long">5.8.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.1/Getopt::Long">5.8.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.0/Getopt::Long">5.8.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.6.2/Getopt::Long">5.6.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.6.1/Getopt::Long">5.6.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.6.0/Getopt::Long">5.6.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.005_04/Getopt::Long">5.005_04</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.005_03/Getopt::Long">5.005_03</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.005_02/Getopt::Long">5.005_02</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.005_01/Getopt::Long">5.005_01</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.005/Getopt::Long">5.005</a>
        </div>
      </li>
      <li class="nav-item dropdown text-nowrap">
        <a class="nav-link dropdown-toggle" href="./Getopt::Long.html#" id="dropdownlink-dev" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Dev</a>
        <div class="dropdown-menu" aria-labelledby="dropdownlink-dev">
          <a class="dropdown-item" href="https://perldoc.perl.org/blead/Getopt::Long">blead</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.39.6/Getopt::Long">5.39.6</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.39.5/Getopt::Long">5.39.5</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.39.4/Getopt::Long">5.39.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.39.3/Getopt::Long">5.39.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.39.2/Getopt::Long">5.39.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.39.1/Getopt::Long">5.39.1</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.38.0-RC2/Getopt::Long">5.38.0-RC2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.38.0-RC1/Getopt::Long">5.38.0-RC1</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.11/Getopt::Long">5.37.11</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.10/Getopt::Long">5.37.10</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.9/Getopt::Long">5.37.9</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.8/Getopt::Long">5.37.8</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.7/Getopt::Long">5.37.7</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.6/Getopt::Long">5.37.6</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.5/Getopt::Long">5.37.5</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.4/Getopt::Long">5.37.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.3/Getopt::Long">5.37.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.2/Getopt::Long">5.37.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.1/Getopt::Long">5.37.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.0/Getopt::Long">5.37.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.11/Getopt::Long">5.35.11</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.10/Getopt::Long">5.35.10</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.9/Getopt::Long">5.35.9</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.8/Getopt::Long">5.35.8</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.7/Getopt::Long">5.35.7</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.6/Getopt::Long">5.35.6</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.5/Getopt::Long">5.35.5</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.4/Getopt::Long">5.35.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.3/Getopt::Long">5.35.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.2/Getopt::Long">5.35.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.1/Getopt::Long">5.35.1</a>
          <a class="dropdown-item active" href="./Getopt::Long.html">5.35.0</a>
        </div>
      </li>
      <li class="nav-item dropdown text-nowrap">
        <a class="nav-link dropdown-toggle" href="./Getopt::Long.html#" id="dropdownlink-nav" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Documentation</a>
        <div class="dropdown-menu" aria-labelledby="dropdownlink-nav">
          <a class="dropdown-item" href="perl.html">Perl</a>
          <a class="dropdown-item" href="perlintro.html">Intro</a>
          <a class="dropdown-item" href="perl.html#Tutorials">Tutorials</a>
          <a class="dropdown-item" href="perlfaq.html">FAQs</a>
          <a class="dropdown-item" href="perl.html#Reference-Manual">Reference</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="perlop.html">Operators</a>
          <a class="dropdown-item" href="functions.html">Functions</a>
          <a class="dropdown-item" href="variables.html">Variables</a>
          <a class="dropdown-item" href="modules.html">Modules</a>
          <a class="dropdown-item" href="perlutil.html">Utilities</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="perlcommunity.html">Community</a>
          <a class="dropdown-item" href="perlhist.html">History</a>
        </div>
      </li>
    </ul>
    <ul class="navbar-nav">
      <script>
        function set_expand (expand) {
          var perldocdiv = document.getElementById('perldocdiv');
          var width = window.getComputedStyle(perldocdiv).getPropertyValue('max-width');
          var expanded = (width == '' || width == 'none') ? true : false;
          if (expand === null) {
            expand = !expanded;
          }
          if ((expand && !expanded) || (!expand && expanded)) {
            perldocdiv.style.setProperty('max-width', expand ? 'none' : '960px');
            var button_classlist = document.getElementById('content-expand-button').classList;
            if (expand) {
              button_classlist.add('btn-light');
              button_classlist.remove('btn-outline-light');
            } else {
              button_classlist.add('btn-outline-light');
              button_classlist.remove('btn-light');
            }
          }
          return expand;
        }
        function toggle_expand () {
          var expand = set_expand(null);
          document.cookie = 'perldoc_expand=' + (expand ? 1 : 0) + '; path=/; expires=Tue, 19 Jan 2038 03:14:07 UTC';
        }
        function read_expand () {
          return document.cookie.split(';').some(function (item) { return item.indexOf('perldoc_expand=1') >= 0 });
        }
        if (document.readyState === 'loading') {
          document.addEventListener('DOMContentLoaded', function () {
            if (read_expand()) {
              set_expand(true);
            }
          });
        } else if (read_expand()) {
          set_expand(true);
        }
      </script>
      <button id="content-expand-button" type="button" class="btn btn-outline-light d-none d-lg-inline-block mr-2" onclick="toggle_expand()">Expand</button>
    <ul>
    <form class="form-inline" method="get" action="https://perldoc.perl.org/5.35.0/search">
      <input class="form-control mr-3" type="search" name="q" placeholder="Search" aria-label="Search">
    </form>
  </div>
</nav>

    <div id="wrapperlicious" class="container-fluid">
      <div id="perldocdiv">
        <div id="links">
          <a href="./Getopt::Long.html">Getopt::Long</a>
          <div id="more">
            (<a href="./Getopt::Long.txt">source</a>,
            <a href="https://metacpan.org/pod/Getopt::Long">CPAN</a>)
          </div>
            <div id="moduleversion">version 2.52</div>
        </div>
        <div class="leading-notice">
          You are viewing the version of this documentation from Perl 5.35.0.
            This is a development version of Perl.
        </div>
        <h1><a id="toc">CONTENTS</a></h1>
                  <ul>
              <li>
                <a class="text-decoration-none" href="./Getopt::Long.html#NAME">NAME</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./Getopt::Long.html#SYNOPSIS">SYNOPSIS</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./Getopt::Long.html#DESCRIPTION">DESCRIPTION</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./Getopt::Long.html#Command-Line-Options,-an-Introduction">Command Line Options, an Introduction</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./Getopt::Long.html#Getting-Started-with-Getopt::Long">Getting Started with Getopt::Long</a>
                            <ul>
              <li>
                <a class="text-decoration-none" href="./Getopt::Long.html#Simple-options">Simple options</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./Getopt::Long.html#A-little-bit-less-simple-options">A little bit less simple options</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./Getopt::Long.html#Mixing-command-line-option-with-other-arguments">Mixing command line option with other arguments</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./Getopt::Long.html#Options-with-values">Options with values</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./Getopt::Long.html#Options-with-multiple-values">Options with multiple values</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./Getopt::Long.html#Options-with-hash-values">Options with hash values</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./Getopt::Long.html#User-defined-subroutines-to-handle-options">User-defined subroutines to handle options</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./Getopt::Long.html#Options-with-multiple-names">Options with multiple names</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./Getopt::Long.html#Case-and-abbreviations">Case and abbreviations</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./Getopt::Long.html#Summary-of-Option-Specifications">Summary of Option Specifications</a>
              </li>
          </ul>

              </li>
              <li>
                <a class="text-decoration-none" href="./Getopt::Long.html#Advanced-Possibilities">Advanced Possibilities</a>
                            <ul>
              <li>
                <a class="text-decoration-none" href="./Getopt::Long.html#Object-oriented-interface">Object oriented interface</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./Getopt::Long.html#Callback-object">Callback object</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./Getopt::Long.html#Thread-Safety">Thread Safety</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./Getopt::Long.html#Documentation-and-help-texts">Documentation and help texts</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./Getopt::Long.html#Parsing-options-from-an-arbitrary-array">Parsing options from an arbitrary array</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./Getopt::Long.html#Parsing-options-from-an-arbitrary-string">Parsing options from an arbitrary string</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./Getopt::Long.html#Storing-options-values-in-a-hash">Storing options values in a hash</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./Getopt::Long.html#Bundling">Bundling</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./Getopt::Long.html#The-lonesome-dash">The lonesome dash</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./Getopt::Long.html#Argument-callback">Argument callback</a>
              </li>
          </ul>

              </li>
              <li>
                <a class="text-decoration-none" href="./Getopt::Long.html#Configuring-Getopt::Long">Configuring Getopt::Long</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./Getopt::Long.html#Exportable-Methods">Exportable Methods</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./Getopt::Long.html#Return-values-and-Errors">Return values and Errors</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./Getopt::Long.html#Legacy">Legacy</a>
                            <ul>
              <li>
                <a class="text-decoration-none" href="./Getopt::Long.html#Default-destinations">Default destinations</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./Getopt::Long.html#Alternative-option-starters">Alternative option starters</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./Getopt::Long.html#Configuration-variables">Configuration variables</a>
              </li>
          </ul>

              </li>
              <li>
                <a class="text-decoration-none" href="./Getopt::Long.html#Tips-and-Techniques">Tips and Techniques</a>
                            <ul>
              <li>
                <a class="text-decoration-none" href="./Getopt::Long.html#Pushing-multiple-values-in-a-hash-option">Pushing multiple values in a hash option</a>
              </li>
          </ul>

              </li>
              <li>
                <a class="text-decoration-none" href="./Getopt::Long.html#Troubleshooting">Troubleshooting</a>
                            <ul>
              <li>
                <a class="text-decoration-none" href="./Getopt::Long.html#GetOptions-does-not-return-a-false-result-when-an-option-is-not-supplied">GetOptions does not return a false result when an option is not supplied</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./Getopt::Long.html#GetOptions-does-not-split-the-command-line-correctly">GetOptions does not split the command line correctly</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./Getopt::Long.html#Undefined-subroutine-&amp;main::GetOptions-called">Undefined subroutine &amp;main::GetOptions called</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./Getopt::Long.html#How-do-I-put-a-%22-?%22-option-into-a-Getopt::Long?">How do I put a &quot;-?&quot; option into a Getopt::Long?</a>
              </li>
          </ul>

              </li>
              <li>
                <a class="text-decoration-none" href="./Getopt::Long.html#AUTHOR">AUTHOR</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./Getopt::Long.html#COPYRIGHT-AND-DISCLAIMER">COPYRIGHT AND DISCLAIMER</a>
              </li>
          </ul>

      <h1 id="NAME"><a class="permalink" href="./Getopt::Long.html#NAME">#</a>NAME</h1>

<p>Getopt::Long - Extended processing of command line options</p>

<h1 id="SYNOPSIS"><a class="permalink" href="./Getopt::Long.html#SYNOPSIS">#</a>SYNOPSIS</h1>

<pre><code>use Getopt::Long;
my $data   = &quot;file.dat&quot;;
my $length = 24;
my $verbose;
GetOptions (&quot;length=i&quot; =&gt; \$length,    # numeric
            &quot;file=s&quot;   =&gt; \$data,      # string
            &quot;verbose&quot;  =&gt; \$verbose)   # flag
or die(&quot;Error in command line arguments\n&quot;);</code></pre>

<h1 id="DESCRIPTION"><a class="permalink" href="./Getopt::Long.html#DESCRIPTION">#</a>DESCRIPTION</h1>

<p>The Getopt::Long module implements an extended getopt function called GetOptions(). It parses the command line from <code>@ARGV</code>, recognizing and removing specified options and their possible values.</p>

<p>This function adheres to the POSIX syntax for command line options, with GNU extensions. In general, this means that options have long names instead of single letters, and are introduced with a double dash &quot;--&quot;. Support for bundling of command line options, as was the case with the more traditional single-letter approach, is provided but not enabled by default.</p>

<h1 id="Command-Line-Options,-an-Introduction"><a class="permalink" href="./Getopt::Long.html#Command-Line-Options,-an-Introduction">#</a><a id="Command"></a><a id="Command-Line-Options-an-Introduction"></a>Command Line Options, an Introduction</h1>

<p>Command line operated programs traditionally take their arguments from the command line, for example filenames or other information that the program needs to know. Besides arguments, these programs often take command line <i>options</i> as well. Options are not necessary for the program to work, hence the name &#39;option&#39;, but are used to modify its default behaviour. For example, a program could do its job quietly, but with a suitable option it could provide verbose information about what it did.</p>

<p>Command line options come in several flavours. Historically, they are preceded by a single dash <code>-</code>, and consist of a single letter.</p>

<pre><code class="plaintext">-l -a -c</code></pre>

<p>Usually, these single-character options can be bundled:</p>

<pre><code class="plaintext">-lac</code></pre>

<p>Options can have values, the value is placed after the option character. Sometimes with whitespace in between, sometimes not:</p>

<pre><code class="plaintext">-s 24 -s24</code></pre>

<p>Due to the very cryptic nature of these options, another style was developed that used long names. So instead of a cryptic <code>-l</code> one could use the more descriptive <code>--long</code>. To distinguish between a bundle of single-character options and a long one, two dashes are used to precede the option name. Early implementations of long options used a plus <code>+</code> instead. Also, option values could be specified either like</p>

<pre><code class="plaintext">--size=24</code></pre>

<p>or</p>

<pre><code class="plaintext">--size 24</code></pre>

<p>The <code>+</code> form is now obsolete and strongly deprecated.</p>

<h1 id="Getting-Started-with-Getopt::Long"><a class="permalink" href="./Getopt::Long.html#Getting-Started-with-Getopt::Long">#</a><a id="Getting"></a>Getting Started with Getopt::Long</h1>

<p>Getopt::Long is the Perl5 successor of <code>newgetopt.pl</code>. This was the first Perl module that provided support for handling the new style of command line options, in particular long option names, hence the Perl5 name Getopt::Long. This module also supports single-character options and bundling.</p>

<p>To use Getopt::Long from a Perl program, you must include the following line in your Perl program:</p>

<pre><code>use Getopt::Long;</code></pre>

<p>This will load the core of the Getopt::Long module and prepare your program for using it. Most of the actual Getopt::Long code is not loaded until you really call one of its functions.</p>

<p>In the default configuration, options names may be abbreviated to uniqueness, case does not matter, and a single dash is sufficient, even for long option names. Also, options may be placed between non-option arguments. See <a href="./Getopt::Long.html#Configuring-Getopt%3A%3ALong">&quot;Configuring Getopt::Long&quot;</a> for more details on how to configure Getopt::Long.</p>

<h2 id="Simple-options"><a class="permalink" href="./Getopt::Long.html#Simple-options">#</a><a id="Simple"></a>Simple options</h2>

<p>The most simple options are the ones that take no values. Their mere presence on the command line enables the option. Popular examples are:</p>

<pre><code class="plaintext">--all --verbose --quiet --debug</code></pre>

<p>Handling simple options is straightforward:</p>

<pre><code>my $verbose = &#39;&#39;;	# option variable with default value (false)
my $all = &#39;&#39;;	# option variable with default value (false)
GetOptions (&#39;verbose&#39; =&gt; \$verbose, &#39;all&#39; =&gt; \$all);</code></pre>

<p>The call to GetOptions() parses the command line arguments that are present in <code>@ARGV</code> and sets the option variable to the value <code>1</code> if the option did occur on the command line. Otherwise, the option variable is not touched. Setting the option value to true is often called <i>enabling</i> the option.</p>

<p>The option name as specified to the GetOptions() function is called the option <i>specification</i>. Later we&#39;ll see that this specification can contain more than just the option name. The reference to the variable is called the option <i>destination</i>.</p>

<p>GetOptions() will return a true value if the command line could be processed successfully. Otherwise, it will write error messages using die() and warn(), and return a false result.</p>

<h2 id="A-little-bit-less-simple-options"><a class="permalink" href="./Getopt::Long.html#A-little-bit-less-simple-options">#</a><a id="A"></a>A little bit less simple options</h2>

<p>Getopt::Long supports two useful variants of simple options: <i>negatable</i> options and <i>incremental</i> options.</p>

<p>A negatable option is specified with an exclamation mark <code>!</code> after the option name:</p>

<pre><code>my $verbose = &#39;&#39;;	# option variable with default value (false)
GetOptions (&#39;verbose!&#39; =&gt; \$verbose);</code></pre>

<p>Now, using <code>--verbose</code> on the command line will enable <code>$verbose</code>, as expected. But it is also allowed to use <code>--noverbose</code>, which will disable <code>$verbose</code> by setting its value to <code>0</code>. Using a suitable default value, the program can find out whether <code>$verbose</code> is false by default, or disabled by using <code>--noverbose</code>.</p>

<p>An incremental option is specified with a plus <code>+</code> after the option name:</p>

<pre><code>my $verbose = &#39;&#39;;	# option variable with default value (false)
GetOptions (&#39;verbose+&#39; =&gt; \$verbose);</code></pre>

<p>Using <code>--verbose</code> on the command line will increment the value of <code>$verbose</code>. This way the program can keep track of how many times the option occurred on the command line. For example, each occurrence of <code>--verbose</code> could increase the verbosity level of the program.</p>

<h2 id="Mixing-command-line-option-with-other-arguments"><a class="permalink" href="./Getopt::Long.html#Mixing-command-line-option-with-other-arguments">#</a><a id="Mixing"></a>Mixing command line option with other arguments</h2>

<p>Usually programs take command line options as well as other arguments, for example, file names. It is good practice to always specify the options first, and the other arguments last. Getopt::Long will, however, allow the options and arguments to be mixed and &#39;filter out&#39; all the options before passing the rest of the arguments to the program. To stop Getopt::Long from processing further arguments, insert a double dash <code>--</code> on the command line:</p>

<pre><code class="plaintext">--size 24 -- --all</code></pre>

<p>In this example, <code>--all</code> will <i>not</i> be treated as an option, but passed to the program unharmed, in <code>@ARGV</code>.</p>

<h2 id="Options-with-values"><a class="permalink" href="./Getopt::Long.html#Options-with-values">#</a><a id="Options"></a>Options with values</h2>

<p>For options that take values it must be specified whether the option value is required or not, and what kind of value the option expects.</p>

<p>Three kinds of values are supported: integer numbers, floating point numbers, and strings.</p>

<p>If the option value is required, Getopt::Long will take the command line argument that follows the option and assign this to the option variable. If, however, the option value is specified as optional, this will only be done if that value does not look like a valid command line option itself.</p>

<pre><code>my $tag = &#39;&#39;;	# option variable with default value
GetOptions (&#39;tag=s&#39; =&gt; \$tag);</code></pre>

<p>In the option specification, the option name is followed by an equals sign <code>=</code> and the letter <code>s</code>. The equals sign indicates that this option requires a value. The letter <code>s</code> indicates that this value is an arbitrary string. Other possible value types are <code>i</code> for integer values, and <code>f</code> for floating point values. Using a colon <code>:</code> instead of the equals sign indicates that the option value is optional. In this case, if no suitable value is supplied, string valued options get an empty string <code>&#39;&#39;</code> assigned, while numeric options are set to <code>0</code>.</p>

<h2 id="Options-with-multiple-values"><a class="permalink" href="./Getopt::Long.html#Options-with-multiple-values">#</a><a id="Options1"></a>Options with multiple values</h2>

<p>Options sometimes take several values. For example, a program could use multiple directories to search for library files:</p>

<pre><code class="plaintext">--library lib/stdlib --library lib/extlib</code></pre>

<p>To accomplish this behaviour, simply specify an array reference as the destination for the option:</p>

<pre><code>GetOptions (&quot;library=s&quot; =&gt; \@libfiles);</code></pre>

<p>Alternatively, you can specify that the option can have multiple values by adding a &quot;@&quot;, and pass a reference to a scalar as the destination:</p>

<pre><code>GetOptions (&quot;library=s@&quot; =&gt; \$libfiles);</code></pre>

<p>Used with the example above, <code>@libfiles</code> c.q. <code>@$libfiles</code> would contain two strings upon completion: <code>&quot;lib/stdlib&quot;</code> and <code>&quot;lib/extlib&quot;</code>, in that order. It is also possible to specify that only integer or floating point numbers are acceptable values.</p>

<p>Often it is useful to allow comma-separated lists of values as well as multiple occurrences of the options. This is easy using Perl&#39;s split() and join() operators:</p>

<pre><code>GetOptions (&quot;library=s&quot; =&gt; \@libfiles);
@libfiles = split(/,/,join(&#39;,&#39;,@libfiles));</code></pre>

<p>Of course, it is important to choose the right separator string for each purpose.</p>

<p>Warning: What follows is an experimental feature.</p>

<p>Options can take multiple values at once, for example</p>

<pre><code class="plaintext">--coordinates 52.2 16.4 --rgbcolor 255 255 149</code></pre>

<p>This can be accomplished by adding a repeat specifier to the option specification. Repeat specifiers are very similar to the <code>{...}</code> repeat specifiers that can be used with regular expression patterns. For example, the above command line would be handled as follows:</p>

<pre><code>GetOptions(&#39;coordinates=f{2}&#39; =&gt; \@coor, &#39;rgbcolor=i{3}&#39; =&gt; \@color);</code></pre>

<p>The destination for the option must be an array or array reference.</p>

<p>It is also possible to specify the minimal and maximal number of arguments an option takes. <code>foo=s{2,4}</code> indicates an option that takes at least two and at most 4 arguments. <code>foo=s{1,}</code> indicates one or more values; <code>foo:s{,}</code> indicates zero or more option values.</p>

<h2 id="Options-with-hash-values"><a class="permalink" href="./Getopt::Long.html#Options-with-hash-values">#</a><a id="Options2"></a>Options with hash values</h2>

<p>If the option destination is a reference to a hash, the option will take, as value, strings of the form <i>key</i><code>=</code><i>value</i>. The value will be stored with the specified key in the hash.</p>

<pre><code>GetOptions (&quot;define=s&quot; =&gt; \%defines);</code></pre>

<p>Alternatively you can use:</p>

<pre><code>GetOptions (&quot;define=s%&quot; =&gt; \$defines);</code></pre>

<p>When used with command line options:</p>

<pre><code class="plaintext">--define os=linux --define vendor=redhat</code></pre>

<p>the hash <code>%defines</code> (or <code>%$defines</code>) will contain two keys, <code>&quot;os&quot;</code> with value <code>&quot;linux&quot;</code> and <code>&quot;vendor&quot;</code> with value <code>&quot;redhat&quot;</code>. It is also possible to specify that only integer or floating point numbers are acceptable values. The keys are always taken to be strings.</p>

<h2 id="User-defined-subroutines-to-handle-options"><a class="permalink" href="./Getopt::Long.html#User-defined-subroutines-to-handle-options">#</a><a id="User"></a>User-defined subroutines to handle options</h2>

<p>Ultimate control over what should be done when (actually: each time) an option is encountered on the command line can be achieved by designating a reference to a subroutine (or an anonymous subroutine) as the option destination. When GetOptions() encounters the option, it will call the subroutine with two or three arguments. The first argument is the name of the option. (Actually, it is an object that stringifies to the name of the option.) For a scalar or array destination, the second argument is the value to be stored. For a hash destination, the second argument is the key to the hash, and the third argument the value to be stored. It is up to the subroutine to store the value, or do whatever it thinks is appropriate.</p>

<p>A trivial application of this mechanism is to implement options that are related to each other. For example:</p>

<pre><code>    my $verbose = &#39;&#39;;	# option variable with default value (false)
    GetOptions (&#39;verbose&#39; =&gt; \$verbose,
	        &#39;quiet&#39;   =&gt; sub { $verbose = 0 });</code></pre>

<p>Here <code>--verbose</code> and <code>--quiet</code> control the same variable <code>$verbose</code>, but with opposite values.</p>

<p>If the subroutine needs to signal an error, it should call die() with the desired error message as its argument. GetOptions() will catch the die(), issue the error message, and record that an error result must be returned upon completion.</p>

<p>If the text of the error message starts with an exclamation mark <code>!</code> it is interpreted specially by GetOptions(). There is currently one special command implemented: <code>die(&quot;!FINISH&quot;)</code> will cause GetOptions() to stop processing options, as if it encountered a double dash <code>--</code>.</p>

<p>Here is an example of how to access the option name and value from within a subroutine:</p>

<pre><code>GetOptions (&#39;opt=i&#39; =&gt; \&amp;handler);
sub handler {
    my ($opt_name, $opt_value) = @_;
    print(&quot;Option name is $opt_name and value is $opt_value\n&quot;);
}</code></pre>

<h2 id="Options-with-multiple-names"><a class="permalink" href="./Getopt::Long.html#Options-with-multiple-names">#</a><a id="Options3"></a>Options with multiple names</h2>

<p>Often it is user friendly to supply alternate mnemonic names for options. For example <code>--height</code> could be an alternate name for <code>--length</code>. Alternate names can be included in the option specification, separated by vertical bar <code>|</code> characters. To implement the above example:</p>

<pre><code>GetOptions (&#39;length|height=f&#39; =&gt; \$length);</code></pre>

<p>The first name is called the <i>primary</i> name, the other names are called <i>aliases</i>. When using a hash to store options, the key will always be the primary name.</p>

<p>Multiple alternate names are possible.</p>

<h2 id="Case-and-abbreviations"><a class="permalink" href="./Getopt::Long.html#Case-and-abbreviations">#</a><a id="Case"></a>Case and abbreviations</h2>

<p>Without additional configuration, GetOptions() will ignore the case of option names, and allow the options to be abbreviated to uniqueness.</p>

<pre><code>GetOptions (&#39;length|height=f&#39; =&gt; \$length, &quot;head&quot; =&gt; \$head);</code></pre>

<p>This call will allow <code>--l</code> and <code>--L</code> for the length option, but requires a least <code>--hea</code> and <code>--hei</code> for the head and height options.</p>

<h2 id="Summary-of-Option-Specifications"><a class="permalink" href="./Getopt::Long.html#Summary-of-Option-Specifications">#</a><a id="Summary"></a>Summary of Option Specifications</h2>

<p>Each option specifier consists of two parts: the name specification and the argument specification.</p>

<p>The name specification contains the name of the option, optionally followed by a list of alternative names separated by vertical bar characters.</p>

<pre><code class="plaintext">length	      option name is &quot;length&quot;
length|size|l     name is &quot;length&quot;, aliases are &quot;size&quot; and &quot;l&quot;</code></pre>

<p>The argument specification is optional. If omitted, the option is considered boolean, a value of 1 will be assigned when the option is used on the command line.</p>

<p>The argument specification can be</p>

<dl>

<dt id="!"><a class="permalink" href="./Getopt::Long.html#!">#</a><a id="pod"></a>!</dt>
<dd>

<p>The option does not take an argument and may be negated by prefixing it with &quot;no&quot; or &quot;no-&quot;. E.g. <code>&quot;foo!&quot;</code> will allow <code>--foo</code> (a value of 1 will be assigned) as well as <code>--nofoo</code> and <code>--no-foo</code> (a value of 0 will be assigned). If the option has aliases, this applies to the aliases as well.</p>

<p>Using negation on a single letter option when bundling is in effect is pointless and will result in a warning.</p>

</dd>
<dt id="+"><a class="permalink" href="./Getopt::Long.html#+">#</a><a id="pod1"></a>+</dt>
<dd>

<p>The option does not take an argument and will be incremented by 1 every time it appears on the command line. E.g. <code>&quot;more+&quot;</code>, when used with <code>--more --more --more</code>, will increment the value three times, resulting in a value of 3 (provided it was 0 or undefined at first).</p>

<p>The <code>+</code> specifier is ignored if the option destination is not a scalar.</p>

</dd>
<dt id="=-type-[-desttype-]-[-repeat-]"><a class="permalink" href="./Getopt::Long.html#=-type-%5B-desttype-%5D-%5B-repeat-%5D">#</a><a id="type-desttype-repeat"></a>= <i>type</i> [ <i>desttype</i> ] [ <i>repeat</i> ]</dt>
<dd>

<p>The option requires an argument of the given type. Supported types are:</p>

<dl>

<dt id="s"><a class="permalink" href="./Getopt::Long.html#s">#</a>s</dt>
<dd>

<p>String. An arbitrary sequence of characters. It is valid for the argument to start with <code>-</code> or <code>--</code>.</p>

</dd>
<dt id="i"><a class="permalink" href="./Getopt::Long.html#i">#</a>i</dt>
<dd>

<p>Integer. An optional leading plus or minus sign, followed by a sequence of digits.</p>

</dd>
<dt id="o"><a class="permalink" href="./Getopt::Long.html#o">#</a>o</dt>
<dd>

<p>Extended integer, Perl style. This can be either an optional leading plus or minus sign, followed by a sequence of digits, or an octal string (a zero, optionally followed by &#39;0&#39;, &#39;1&#39;, .. &#39;7&#39;), or a hexadecimal string (<code>0x</code> followed by &#39;0&#39; .. &#39;9&#39;, &#39;a&#39; .. &#39;f&#39;, case insensitive), or a binary string (<code>0b</code> followed by a series of &#39;0&#39; and &#39;1&#39;).</p>

</dd>
<dt id="f"><a class="permalink" href="./Getopt::Long.html#f">#</a>f</dt>
<dd>

<p>Real number. For example <code>3.14</code>, <code>-6.23E24</code> and so on.</p>

</dd>
</dl>

<p>The <i>desttype</i> can be <code>@</code> or <code>%</code> to specify that the option is list or a hash valued. This is only needed when the destination for the option value is not otherwise specified. It should be omitted when not needed.</p>

<p>The <i>repeat</i> specifies the number of values this option takes per occurrence on the command line. It has the format <code>{</code> [ <i>min</i> ] [ <code>,</code> [ <i>max</i> ] ] <code>}</code>.</p>

<p><i>min</i> denotes the minimal number of arguments. It defaults to 1 for options with <code>=</code> and to 0 for options with <code>:</code>, see below. Note that <i>min</i> overrules the <code>=</code> / <code>:</code> semantics.</p>

<p><i>max</i> denotes the maximum number of arguments. It must be at least <i>min</i>. If <i>max</i> is omitted, <i>but the comma is not</i>, there is no upper bound to the number of argument values taken.</p>

</dd>
<dt id=":-type-[-desttype-]"><a class="permalink" href="./Getopt::Long.html#:-type-%5B-desttype-%5D">#</a><a id="type-desttype"></a>: <i>type</i> [ <i>desttype</i> ]</dt>
<dd>

<p>Like <code>=</code>, but designates the argument as optional. If omitted, an empty string will be assigned to string values options, and the value zero to numeric options.</p>

<p>Note that if a string argument starts with <code>-</code> or <code>--</code>, it will be considered an option on itself.</p>

</dd>
<dt id=":-number-[-desttype-]"><a class="permalink" href="./Getopt::Long.html#:-number-%5B-desttype-%5D">#</a><a id="number-desttype"></a>: <i>number</i> [ <i>desttype</i> ]</dt>
<dd>

<p>Like <code>:i</code>, but if the value is omitted, the <i>number</i> will be assigned.</p>

</dd>
<dt id=":-+-[-desttype-]"><a class="permalink" href="./Getopt::Long.html#:-+-%5B-desttype-%5D">#</a><a id="desttype"></a>: + [ <i>desttype</i> ]</dt>
<dd>

<p>Like <code>:i</code>, but if the value is omitted, the current value for the option will be incremented.</p>

</dd>
</dl>

<h1 id="Advanced-Possibilities"><a class="permalink" href="./Getopt::Long.html#Advanced-Possibilities">#</a><a id="Advanced"></a>Advanced Possibilities</h1>

<h2 id="Object-oriented-interface"><a class="permalink" href="./Getopt::Long.html#Object-oriented-interface">#</a><a id="Object"></a>Object oriented interface</h2>

<p>Getopt::Long can be used in an object oriented way as well:</p>

<pre><code>use Getopt::Long;
$p = Getopt::Long::Parser-&gt;new;
$p-&gt;configure(...configuration options...);
if ($p-&gt;getoptions(...options descriptions...)) ...
if ($p-&gt;getoptionsfromarray( \@array, ...options descriptions...)) ...</code></pre>

<p>Configuration options can be passed to the constructor:</p>

<pre><code>$p = new Getopt::Long::Parser
         config =&gt; [...configuration options...];</code></pre>

<h2 id="Callback-object"><a class="permalink" href="./Getopt::Long.html#Callback-object">#</a><a id="Callback"></a>Callback object</h2>

<p>In version 2.37 the first argument to the callback function was changed from string to object. This was done to make room for extensions and more detailed control. The object stringifies to the option name so this change should not introduce compatibility problems.</p>

<p>The callback object has the following methods:</p>

<dl>

<dt id="name"><a class="permalink" href="./Getopt::Long.html#name">#</a>name</dt>
<dd>

<p>The name of the option, unabbreviated. For an option with multiple names it return the first (canonical) name.</p>

</dd>
<dt id="given"><a class="permalink" href="./Getopt::Long.html#given">#</a>given</dt>
<dd>

<p>The name of the option as actually used, unabbreveated.</p>

</dd>
</dl>

<h2 id="Thread-Safety"><a class="permalink" href="./Getopt::Long.html#Thread-Safety">#</a><a id="Thread"></a>Thread Safety</h2>

<p>Getopt::Long is thread safe when using ithreads as of Perl 5.8. It is <i>not</i> thread safe when using the older (experimental and now obsolete) threads implementation that was added to Perl 5.005.</p>

<h2 id="Documentation-and-help-texts"><a class="permalink" href="./Getopt::Long.html#Documentation-and-help-texts">#</a><a id="Documentation"></a>Documentation and help texts</h2>

<p>Getopt::Long encourages the use of Pod::Usage to produce help messages. For example:</p>

<pre><code>use Getopt::Long;
use Pod::Usage;

my $man = 0;
my $help = 0;

GetOptions(&#39;help|?&#39; =&gt; \$help, man =&gt; \$man) or pod2usage(2);
pod2usage(1) if $help;
pod2usage(-exitval =&gt; 0, -verbose =&gt; 2) if $man;

__END__

=head1 NAME

sample - Using Getopt::Long and Pod::Usage

=head1 SYNOPSIS

sample [options] [file ...]

 Options:
   -help            brief help message
   -man             full documentation

=head1 OPTIONS

=over 8

=item B&lt;-help&gt;

Print a brief help message and exits.

=item B&lt;-man&gt;

Prints the manual page and exits.

=back

=head1 DESCRIPTION

B&lt;This program&gt; will read the given input file(s) and do something
useful with the contents thereof.

=cut</code></pre>

<p>See <a href="./Pod::Usage.html">Pod::Usage</a> for details.</p>

<h2 id="Parsing-options-from-an-arbitrary-array"><a class="permalink" href="./Getopt::Long.html#Parsing-options-from-an-arbitrary-array">#</a><a id="Parsing"></a>Parsing options from an arbitrary array</h2>

<p>By default, GetOptions parses the options that are present in the global array <code>@ARGV</code>. A special entry <code>GetOptionsFromArray</code> can be used to parse options from an arbitrary array.</p>

<pre><code>use Getopt::Long qw(GetOptionsFromArray);
$ret = GetOptionsFromArray(\@myopts, ...);</code></pre>

<p>When used like this, options and their possible values are removed from <code>@myopts</code>, the global <code>@ARGV</code> is not touched at all.</p>

<p>The following two calls behave identically:</p>

<pre><code>$ret = GetOptions( ... );
$ret = GetOptionsFromArray(\@ARGV, ... );</code></pre>

<p>This also means that a first argument hash reference now becomes the second argument:</p>

<pre><code>$ret = GetOptions(\%opts, ... );
$ret = GetOptionsFromArray(\@ARGV, \%opts, ... );</code></pre>

<h2 id="Parsing-options-from-an-arbitrary-string"><a class="permalink" href="./Getopt::Long.html#Parsing-options-from-an-arbitrary-string">#</a><a id="Parsing1"></a>Parsing options from an arbitrary string</h2>

<p>A special entry <code>GetOptionsFromString</code> can be used to parse options from an arbitrary string.</p>

<pre><code>use Getopt::Long qw(GetOptionsFromString);
$ret = GetOptionsFromString($string, ...);</code></pre>

<p>The contents of the string are split into arguments using a call to <code>Text::ParseWords::shellwords</code>. As with <code>GetOptionsFromArray</code>, the global <code>@ARGV</code> is not touched.</p>

<p>It is possible that, upon completion, not all arguments in the string have been processed. <code>GetOptionsFromString</code> will, when called in list context, return both the return status and an array reference to any remaining arguments:</p>

<pre><code>($ret, $args) = GetOptionsFromString($string, ... );</code></pre>

<p>If any arguments remain, and <code>GetOptionsFromString</code> was not called in list context, a message will be given and <code>GetOptionsFromString</code> will return failure.</p>

<p>As with GetOptionsFromArray, a first argument hash reference now becomes the second argument. See the next section.</p>

<h2 id="Storing-options-values-in-a-hash"><a class="permalink" href="./Getopt::Long.html#Storing-options-values-in-a-hash">#</a><a id="Storing"></a>Storing options values in a hash</h2>

<p>Sometimes, for example when there are a lot of options, having a separate variable for each of them can be cumbersome. GetOptions() supports, as an alternative mechanism, storing options values in a hash.</p>

<p>To obtain this, a reference to a hash must be passed <i>as the first argument</i> to GetOptions(). For each option that is specified on the command line, the option value will be stored in the hash with the option name as key. Options that are not actually used on the command line will not be put in the hash, on other words, <code>exists($h{option})</code> (or defined()) can be used to test if an option was used. The drawback is that warnings will be issued if the program runs under <code>use strict</code> and uses <code>$h{option}</code> without testing with exists() or defined() first.</p>

<pre><code>my %h = ();
GetOptions (\%h, &#39;length=i&#39;);	# will store in $h{length}</code></pre>

<p>For options that take list or hash values, it is necessary to indicate this by appending an <code>@</code> or <code>%</code> sign after the type:</p>

<pre><code>GetOptions (\%h, &#39;colours=s@&#39;);	# will push to @{$h{colours}}</code></pre>

<p>To make things more complicated, the hash may contain references to the actual destinations, for example:</p>

<pre><code>my $len = 0;
my %h = (&#39;length&#39; =&gt; \$len);
GetOptions (\%h, &#39;length=i&#39;);	# will store in $len</code></pre>

<p>This example is fully equivalent with:</p>

<pre><code>my $len = 0;
GetOptions (&#39;length=i&#39; =&gt; \$len);	# will store in $len</code></pre>

<p>Any mixture is possible. For example, the most frequently used options could be stored in variables while all other options get stored in the hash:</p>

<pre><code>my $verbose = 0;			# frequently referred
my $debug = 0;			# frequently referred
my %h = (&#39;verbose&#39; =&gt; \$verbose, &#39;debug&#39; =&gt; \$debug);
GetOptions (\%h, &#39;verbose&#39;, &#39;debug&#39;, &#39;filter&#39;, &#39;size=i&#39;);
if ( $verbose ) { ... }
if ( exists $h{filter} ) { ... option &#39;filter&#39; was specified ... }</code></pre>

<h2 id="Bundling"><a class="permalink" href="./Getopt::Long.html#Bundling">#</a>Bundling</h2>

<p>With bundling it is possible to set several single-character options at once. For example if <code>a</code>, <code>v</code> and <code>x</code> are all valid options,</p>

<pre><code class="plaintext">-vax</code></pre>

<p>will set all three.</p>

<p>Getopt::Long supports three styles of bundling. To enable bundling, a call to Getopt::Long::Configure is required.</p>

<p>The simplest style of bundling can be enabled with:</p>

<pre><code>Getopt::Long::Configure (&quot;bundling&quot;);</code></pre>

<p>Configured this way, single-character options can be bundled but long options (and any of their auto-abbreviated shortened forms) <b>must</b> always start with a double dash <code>--</code> to avoid ambiguity. For example, when <code>vax</code>, <code>a</code>, <code>v</code> and <code>x</code> are all valid options,</p>

<pre><code class="plaintext">-vax</code></pre>

<p>will set <code>a</code>, <code>v</code> and <code>x</code>, but</p>

<pre><code class="plaintext">--vax</code></pre>

<p>will set <code>vax</code>.</p>

<p>The second style of bundling lifts this restriction. It can be enabled with:</p>

<pre><code>Getopt::Long::Configure (&quot;bundling_override&quot;);</code></pre>

<p>Now, <code>-vax</code> will set the option <code>vax</code>.</p>

<p>In all of the above cases, option values may be inserted in the bundle. For example:</p>

<pre><code class="plaintext">-h24w80</code></pre>

<p>is equivalent to</p>

<pre><code class="plaintext">-h 24 -w 80</code></pre>

<p>A third style of bundling allows only values to be bundled with options. It can be enabled with:</p>

<pre><code>Getopt::Long::Configure (&quot;bundling_values&quot;);</code></pre>

<p>Now, <code>-h24</code> will set the option <code>h</code> to <code>24</code>, but option bundles like <code>-vxa</code> and <code>-h24w80</code> are flagged as errors.</p>

<p>Enabling <code>bundling_values</code> will disable the other two styles of bundling.</p>

<p>When configured for bundling, single-character options are matched case sensitive while long options are matched case insensitive. To have the single-character options matched case insensitive as well, use:</p>

<pre><code>Getopt::Long::Configure (&quot;bundling&quot;, &quot;ignorecase_always&quot;);</code></pre>

<p>It goes without saying that bundling can be quite confusing.</p>

<h2 id="The-lonesome-dash"><a class="permalink" href="./Getopt::Long.html#The-lonesome-dash">#</a><a id="The"></a>The lonesome dash</h2>

<p>Normally, a lone dash <code>-</code> on the command line will not be considered an option. Option processing will terminate (unless &quot;permute&quot; is configured) and the dash will be left in <code>@ARGV</code>.</p>

<p>It is possible to get special treatment for a lone dash. This can be achieved by adding an option specification with an empty name, for example:</p>

<pre><code>GetOptions (&#39;&#39; =&gt; \$stdio);</code></pre>

<p>A lone dash on the command line will now be a legal option, and using it will set variable <code>$stdio</code>.</p>

<h2 id="Argument-callback"><a class="permalink" href="./Getopt::Long.html#Argument-callback">#</a><a id="Argument"></a>Argument callback</h2>

<p>A special option &#39;name&#39; <code>&lt;&gt;</code> can be used to designate a subroutine to handle non-option arguments. When GetOptions() encounters an argument that does not look like an option, it will immediately call this subroutine and passes it one parameter: the argument name.</p>

<p>For example:</p>

<pre><code>my $width = 80;
sub process { ... }
GetOptions (&#39;width=i&#39; =&gt; \$width, &#39;&lt;&gt;&#39; =&gt; \&amp;process);</code></pre>

<p>When applied to the following command line:</p>

<pre><code class="plaintext">arg1 --width=72 arg2 --width=60 arg3</code></pre>

<p>This will call <code>process(&quot;arg1&quot;)</code> while <code>$width</code> is <code>80</code>, <code>process(&quot;arg2&quot;)</code> while <code>$width</code> is <code>72</code>, and <code>process(&quot;arg3&quot;)</code> while <code>$width</code> is <code>60</code>.</p>

<p>This feature requires configuration option <b>permute</b>, see section <a href="./Getopt::Long.html#Configuring-Getopt%3A%3ALong">&quot;Configuring Getopt::Long&quot;</a>.</p>

<h1 id="Configuring-Getopt::Long"><a class="permalink" href="./Getopt::Long.html#Configuring-Getopt::Long">#</a><a id="Configuring"></a>Configuring Getopt::Long</h1>

<p>Getopt::Long can be configured by calling subroutine Getopt::Long::Configure(). This subroutine takes a list of quoted strings, each specifying a configuration option to be enabled, e.g. <code>ignore_case</code>. To disable, prefix with <code>no</code> or <code>no_</code>, e.g. <code>no_ignore_case</code>. Case does not matter. Multiple calls to Configure() are possible.</p>

<p>Alternatively, as of version 2.24, the configuration options may be passed together with the <code>use</code> statement:</p>

<pre><code>use Getopt::Long qw(:config no_ignore_case bundling);</code></pre>

<p>The following options are available:</p>

<dl>

<dt id="default"><a class="permalink" href="./Getopt::Long.html#default">#</a>default</dt>
<dd>

<p>This option causes all configuration options to be reset to their default values.</p>

</dd>
<dt id="posix_default"><a class="permalink" href="./Getopt::Long.html#posix_default">#</a>posix_default</dt>
<dd>

<p>This option causes all configuration options to be reset to their default values as if the environment variable POSIXLY_CORRECT had been set.</p>

</dd>
<dt id="auto_abbrev"><a class="permalink" href="./Getopt::Long.html#auto_abbrev">#</a>auto_abbrev</dt>
<dd>

<p>Allow option names to be abbreviated to uniqueness. Default is enabled unless environment variable POSIXLY_CORRECT has been set, in which case <code>auto_abbrev</code> is disabled.</p>

</dd>
<dt id="getopt_compat"><a class="permalink" href="./Getopt::Long.html#getopt_compat">#</a>getopt_compat</dt>
<dd>

<p>Allow <code>+</code> to start options. Default is enabled unless environment variable POSIXLY_CORRECT has been set, in which case <code>getopt_compat</code> is disabled.</p>

</dd>
<dt id="gnu_compat"><a class="permalink" href="./Getopt::Long.html#gnu_compat">#</a>gnu_compat</dt>
<dd>

<p><code>gnu_compat</code> controls whether <code>--opt=</code> is allowed, and what it should do. Without <code>gnu_compat</code>, <code>--opt=</code> gives an error. With <code>gnu_compat</code>, <code>--opt=</code> will give option <code>opt</code> and empty value. This is the way GNU getopt_long() does it.</p>

<p>Note that <code>--opt value</code> is still accepted, even though GNU getopt_long() doesn&#39;t.</p>

</dd>
<dt id="gnu_getopt"><a class="permalink" href="./Getopt::Long.html#gnu_getopt">#</a>gnu_getopt</dt>
<dd>

<p>This is a short way of setting <code>gnu_compat</code> <code>bundling</code> <code>permute</code> <code>no_getopt_compat</code>. With <code>gnu_getopt</code>, command line handling should be reasonably compatible with GNU getopt_long().</p>

</dd>
<dt id="require_order"><a class="permalink" href="./Getopt::Long.html#require_order">#</a>require_order</dt>
<dd>

<p>Whether command line arguments are allowed to be mixed with options. Default is disabled unless environment variable POSIXLY_CORRECT has been set, in which case <code>require_order</code> is enabled.</p>

<p>See also <code>permute</code>, which is the opposite of <code>require_order</code>.</p>

</dd>
<dt id="permute"><a class="permalink" href="./Getopt::Long.html#permute">#</a>permute</dt>
<dd>

<p>Whether command line arguments are allowed to be mixed with options. Default is enabled unless environment variable POSIXLY_CORRECT has been set, in which case <code>permute</code> is disabled. Note that <code>permute</code> is the opposite of <code>require_order</code>.</p>

<p>If <code>permute</code> is enabled, this means that</p>

<pre><code class="plaintext">--foo arg1 --bar arg2 arg3</code></pre>

<p>is equivalent to</p>

<pre><code class="plaintext">--foo --bar arg1 arg2 arg3</code></pre>

<p>If an argument callback routine is specified, <code>@ARGV</code> will always be empty upon successful return of GetOptions() since all options have been processed. The only exception is when <code>--</code> is used:</p>

<pre><code class="plaintext">--foo arg1 --bar arg2 -- arg3</code></pre>

<p>This will call the callback routine for arg1 and arg2, and then terminate GetOptions() leaving <code>&quot;arg3&quot;</code> in <code>@ARGV</code>.</p>

<p>If <code>require_order</code> is enabled, options processing terminates when the first non-option is encountered.</p>

<pre><code class="plaintext">--foo arg1 --bar arg2 arg3</code></pre>

<p>is equivalent to</p>

<pre><code class="plaintext">--foo -- arg1 --bar arg2 arg3</code></pre>

<p>If <code>pass_through</code> is also enabled, options processing will terminate at the first unrecognized option, or non-option, whichever comes first.</p>

</dd>
<dt id="bundling-(default:-disabled)"><a class="permalink" href="./Getopt::Long.html#bundling-(default:-disabled)">#</a><a id="bundling"></a><a id="bundling-default:-disabled"></a>bundling (default: disabled)</dt>
<dd>

<p>Enabling this option will allow single-character options to be bundled. To distinguish bundles from long option names, long options (and any of their auto-abbreviated shortened forms) <i>must</i> be introduced with <code>--</code> and bundles with <code>-</code>.</p>

<p>Note that, if you have options <code>a</code>, <code>l</code> and <code>all</code>, and auto_abbrev enabled, possible arguments and option settings are:</p>

<pre><code class="plaintext">using argument               sets option(s)
------------------------------------------
-a, --a                      a
-l, --l                      l
-al, -la, -ala, -all,...     a, l
--al, --all                  all</code></pre>

<p>The surprising part is that <code>--a</code> sets option <code>a</code> (due to auto completion), not <code>all</code>.</p>

<p>Note: disabling <code>bundling</code> also disables <code>bundling_override</code>.</p>

</dd>
<dt id="bundling_override-(default:-disabled)"><a class="permalink" href="./Getopt::Long.html#bundling_override-(default:-disabled)">#</a><a id="bundling_override"></a><a id="bundling_override-default:-disabled"></a>bundling_override (default: disabled)</dt>
<dd>

<p>If <code>bundling_override</code> is enabled, bundling is enabled as with <code>bundling</code> but now long option names override option bundles.</p>

<p>Note: disabling <code>bundling_override</code> also disables <code>bundling</code>.</p>

<p><b>Note:</b> Using option bundling can easily lead to unexpected results, especially when mixing long options and bundles. Caveat emptor.</p>

</dd>
<dt id="ignore_case-(default:-enabled)"><a class="permalink" href="./Getopt::Long.html#ignore_case-(default:-enabled)">#</a><a id="ignore_case"></a><a id="ignore_case-default:-enabled"></a>ignore_case (default: enabled)</dt>
<dd>

<p>If enabled, case is ignored when matching option names. If, however, bundling is enabled as well, single character options will be treated case-sensitive.</p>

<p>With <code>ignore_case</code>, option specifications for options that only differ in case, e.g., <code>&quot;foo&quot;</code> and <code>&quot;Foo&quot;</code>, will be flagged as duplicates.</p>

<p>Note: disabling <code>ignore_case</code> also disables <code>ignore_case_always</code>.</p>

</dd>
<dt id="ignore_case_always-(default:-disabled)"><a class="permalink" href="./Getopt::Long.html#ignore_case_always-(default:-disabled)">#</a><a id="ignore_case_always"></a><a id="ignore_case_always-default:-disabled"></a>ignore_case_always (default: disabled)</dt>
<dd>

<p>When bundling is in effect, case is ignored on single-character options also.</p>

<p>Note: disabling <code>ignore_case_always</code> also disables <code>ignore_case</code>.</p>

</dd>
<dt id="auto_version-(default:disabled)"><a class="permalink" href="./Getopt::Long.html#auto_version-(default:disabled)">#</a><a id="auto_version"></a><a id="auto_version-default:disabled"></a>auto_version (default:disabled)</dt>
<dd>

<p>Automatically provide support for the <b>--version</b> option if the application did not specify a handler for this option itself.</p>

<p>Getopt::Long will provide a standard version message that includes the program name, its version (if $main::VERSION is defined), and the versions of Getopt::Long and Perl. The message will be written to standard output and processing will terminate.</p>

<p><code>auto_version</code> will be enabled if the calling program explicitly specified a version number higher than 2.32 in the <code>use</code> or <code>require</code> statement.</p>

</dd>
<dt id="auto_help-(default:disabled)"><a class="permalink" href="./Getopt::Long.html#auto_help-(default:disabled)">#</a><a id="auto_help"></a><a id="auto_help-default:disabled"></a>auto_help (default:disabled)</dt>
<dd>

<p>Automatically provide support for the <b>--help</b> and <b>-?</b> options if the application did not specify a handler for this option itself.</p>

<p>Getopt::Long will provide a help message using module <a href="./Pod::Usage.html">Pod::Usage</a>. The message, derived from the SYNOPSIS POD section, will be written to standard output and processing will terminate.</p>

<p><code>auto_help</code> will be enabled if the calling program explicitly specified a version number higher than 2.32 in the <code>use</code> or <code>require</code> statement.</p>

</dd>
<dt id="pass_through-(default:-disabled)"><a class="permalink" href="./Getopt::Long.html#pass_through-(default:-disabled)">#</a><a id="pass_through"></a><a id="pass_through-default:-disabled"></a>pass_through (default: disabled)</dt>
<dd>

<p>With <code>pass_through</code> anything that is unknown, ambiguous or supplied with an invalid option will not be flagged as an error. Instead the unknown option(s) will be passed to the catchall <code>&lt;&gt;</code> if present, otherwise through to <code>@ARGV</code>. This makes it possible to write wrapper scripts that process only part of the user supplied command line arguments, and pass the remaining options to some other program.</p>

<p>If <code>require_order</code> is enabled, options processing will terminate at the first unrecognized option, or non-option, whichever comes first and all remaining arguments are passed to <code>@ARGV</code> instead of the catchall <code>&lt;&gt;</code> if present. However, if <code>permute</code> is enabled instead, results can become confusing.</p>

<p>Note that the options terminator (default <code>--</code>), if present, will also be passed through in <code>@ARGV</code>.</p>

</dd>
<dt id="prefix"><a class="permalink" href="./Getopt::Long.html#prefix">#</a>prefix</dt>
<dd>

<p>The string that starts options. If a constant string is not sufficient, see <code>prefix_pattern</code>.</p>

</dd>
<dt id="prefix_pattern"><a class="permalink" href="./Getopt::Long.html#prefix_pattern">#</a>prefix_pattern</dt>
<dd>

<p>A Perl pattern that identifies the strings that introduce options. Default is <code>--|-|\+</code> unless environment variable POSIXLY_CORRECT has been set, in which case it is <code>--|-</code>.</p>

</dd>
<dt id="long_prefix_pattern"><a class="permalink" href="./Getopt::Long.html#long_prefix_pattern">#</a>long_prefix_pattern</dt>
<dd>

<p>A Perl pattern that allows the disambiguation of long and short prefixes. Default is <code>--</code>.</p>

<p>Typically you only need to set this if you are using nonstandard prefixes and want some or all of them to have the same semantics as &#39;--&#39; does under normal circumstances.</p>

<p>For example, setting prefix_pattern to <code>--|-|\+|\/</code> and long_prefix_pattern to <code>--|\/</code> would add Win32 style argument handling.</p>

</dd>
<dt id="debug-(default:-disabled)"><a class="permalink" href="./Getopt::Long.html#debug-(default:-disabled)">#</a><a id="debug"></a><a id="debug-default:-disabled"></a>debug (default: disabled)</dt>
<dd>

<p>Enable debugging output.</p>

</dd>
</dl>

<h1 id="Exportable-Methods"><a class="permalink" href="./Getopt::Long.html#Exportable-Methods">#</a><a id="Exportable"></a>Exportable Methods</h1>

<dl>

<dt id="VersionMessage"><a class="permalink" href="./Getopt::Long.html#VersionMessage">#</a>VersionMessage</dt>
<dd>

<p>This subroutine provides a standard version message. Its argument can be:</p>

<ul>

<li><p>A string containing the text of a message to print <i>before</i> printing the standard message.</p>

</li>
<li><p>A numeric value corresponding to the desired exit status.</p>

</li>
<li><p>A reference to a hash.</p>

</li>
</ul>

<p>If more than one argument is given then the entire argument list is assumed to be a hash. If a hash is supplied (either as a reference or as a list) it should contain one or more elements with the following keys:</p>

<dl>

<dt id="-message"><a class="permalink" href="./Getopt::Long.html#-message">#</a><a id="message"></a><code>-message</code></dt>
<dd>

</dd>
<dt id="-msg"><a class="permalink" href="./Getopt::Long.html#-msg">#</a><a id="msg"></a><code>-msg</code></dt>
<dd>

<p>The text of a message to print immediately prior to printing the program&#39;s usage message.</p>

</dd>
<dt id="-exitval"><a class="permalink" href="./Getopt::Long.html#-exitval">#</a><a id="exitval"></a><code>-exitval</code></dt>
<dd>

<p>The desired exit status to pass to the <b>exit()</b> function. This should be an integer, or else the string &quot;NOEXIT&quot; to indicate that control should simply be returned without terminating the invoking process.</p>

</dd>
<dt id="-output"><a class="permalink" href="./Getopt::Long.html#-output">#</a><a id="output"></a><code>-output</code></dt>
<dd>

<p>A reference to a filehandle, or the pathname of a file to which the usage message should be written. The default is <code>\*STDERR</code> unless the exit value is less than 2 (in which case the default is <code>\*STDOUT</code>).</p>

</dd>
</dl>

<p>You cannot tie this routine directly to an option, e.g.:</p>

<pre><code>GetOptions(&quot;version&quot; =&gt; \&amp;VersionMessage);</code></pre>

<p>Use this instead:</p>

<pre><code>GetOptions(&quot;version&quot; =&gt; sub { VersionMessage() });</code></pre>

</dd>
<dt id="HelpMessage"><a class="permalink" href="./Getopt::Long.html#HelpMessage">#</a>HelpMessage</dt>
<dd>

<p>This subroutine produces a standard help message, derived from the program&#39;s POD section SYNOPSIS using <a href="./Pod::Usage.html">Pod::Usage</a>. It takes the same arguments as VersionMessage(). In particular, you cannot tie it directly to an option, e.g.:</p>

<pre><code>GetOptions(&quot;help&quot; =&gt; \&amp;HelpMessage);</code></pre>

<p>Use this instead:</p>

<pre><code>GetOptions(&quot;help&quot; =&gt; sub { HelpMessage() });</code></pre>

</dd>
</dl>

<h1 id="Return-values-and-Errors"><a class="permalink" href="./Getopt::Long.html#Return-values-and-Errors">#</a><a id="Return"></a>Return values and Errors</h1>

<p>Configuration errors and errors in the option definitions are signalled using die() and will terminate the calling program unless the call to Getopt::Long::GetOptions() was embedded in <code>eval { ... }</code>, or die() was trapped using <code>$SIG{__DIE__}</code>.</p>

<p>GetOptions returns true to indicate success. It returns false when the function detected one or more errors during option parsing. These errors are signalled using warn() and can be trapped with <code>$SIG{__WARN__}</code>.</p>

<h1 id="Legacy"><a class="permalink" href="./Getopt::Long.html#Legacy">#</a>Legacy</h1>

<p>The earliest development of <code>newgetopt.pl</code> started in 1990, with Perl version 4. As a result, its development, and the development of Getopt::Long, has gone through several stages. Since backward compatibility has always been extremely important, the current version of Getopt::Long still supports a lot of constructs that nowadays are no longer necessary or otherwise unwanted. This section describes briefly some of these &#39;features&#39;.</p>

<h2 id="Default-destinations"><a class="permalink" href="./Getopt::Long.html#Default-destinations">#</a><a id="Default"></a>Default destinations</h2>

<p>When no destination is specified for an option, GetOptions will store the resultant value in a global variable named <code>opt_</code><i>XXX</i>, where <i>XXX</i> is the primary name of this option. When a program executes under <code>use strict</code> (recommended), these variables must be pre-declared with our() or <code>use vars</code>.</p>

<pre><code>our $opt_length = 0;
GetOptions (&#39;length=i&#39;);	# will store in $opt_length</code></pre>

<p>To yield a usable Perl variable, characters that are not part of the syntax for variables are translated to underscores. For example, <code>--fpp-struct-return</code> will set the variable <code>$opt_fpp_struct_return</code>. Note that this variable resides in the namespace of the calling program, not necessarily <code>main</code>. For example:</p>

<pre><code>GetOptions (&quot;size=i&quot;, &quot;sizes=i@&quot;);</code></pre>

<p>with command line &quot;-size 10 -sizes 24 -sizes 48&quot; will perform the equivalent of the assignments</p>

<pre><code>$opt_size = 10;
@opt_sizes = (24, 48);</code></pre>

<h2 id="Alternative-option-starters"><a class="permalink" href="./Getopt::Long.html#Alternative-option-starters">#</a><a id="Alternative"></a>Alternative option starters</h2>

<p>A string of alternative option starter characters may be passed as the first argument (or the first argument after a leading hash reference argument).</p>

<pre><code>my $len = 0;
GetOptions (&#39;/&#39;, &#39;length=i&#39; =&gt; $len);</code></pre>

<p>Now the command line may look like:</p>

<pre><code class="plaintext">/length 24 -- arg</code></pre>

<p>Note that to terminate options processing still requires a double dash <code>--</code>.</p>

<p>GetOptions() will not interpret a leading <code>&quot;&lt;&gt;&quot;</code> as option starters if the next argument is a reference. To force <code>&quot;&lt;&quot;</code> and <code>&quot;&gt;&quot;</code> as option starters, use <code>&quot;&gt;&lt;&quot;</code>. Confusing? Well, <b>using a starter argument is strongly deprecated</b> anyway.</p>

<h2 id="Configuration-variables"><a class="permalink" href="./Getopt::Long.html#Configuration-variables">#</a><a id="Configuration"></a>Configuration variables</h2>

<p>Previous versions of Getopt::Long used variables for the purpose of configuring. Although manipulating these variables still work, it is strongly encouraged to use the <code>Configure</code> routine that was introduced in version 2.17. Besides, it is much easier.</p>

<h1 id="Tips-and-Techniques"><a class="permalink" href="./Getopt::Long.html#Tips-and-Techniques">#</a><a id="Tips"></a>Tips and Techniques</h1>

<h2 id="Pushing-multiple-values-in-a-hash-option"><a class="permalink" href="./Getopt::Long.html#Pushing-multiple-values-in-a-hash-option">#</a><a id="Pushing"></a>Pushing multiple values in a hash option</h2>

<p>Sometimes you want to combine the best of hashes and arrays. For example, the command line:</p>

<pre><code class="plaintext">--list add=first --list add=second --list add=third</code></pre>

<p>where each successive &#39;list add&#39; option will push the value of add into array ref $list-&gt;{&#39;add&#39;}. The result would be like</p>

<pre><code>$list-&gt;{add} = [qw(first second third)];</code></pre>

<p>This can be accomplished with a destination routine:</p>

<pre><code>GetOptions(&#39;list=s%&#39; =&gt;
             sub { push(@{$list{$_[1]}}, $_[2]) });</code></pre>

<h1 id="Troubleshooting"><a class="permalink" href="./Getopt::Long.html#Troubleshooting">#</a>Troubleshooting</h1>

<h2 id="GetOptions-does-not-return-a-false-result-when-an-option-is-not-supplied"><a class="permalink" href="./Getopt::Long.html#GetOptions-does-not-return-a-false-result-when-an-option-is-not-supplied">#</a><a id="GetOptions"></a>GetOptions does not return a false result when an option is not supplied</h2>

<p>That&#39;s why they&#39;re called &#39;options&#39;.</p>

<h2 id="GetOptions-does-not-split-the-command-line-correctly"><a class="permalink" href="./Getopt::Long.html#GetOptions-does-not-split-the-command-line-correctly">#</a><a id="GetOptions1"></a>GetOptions does not split the command line correctly</h2>

<p>The command line is not split by GetOptions, but by the command line interpreter (CLI). On Unix, this is the shell. On Windows, it is COMMAND.COM or CMD.EXE. Other operating systems have other CLIs.</p>

<p>It is important to know that these CLIs may behave different when the command line contains special characters, in particular quotes or backslashes. For example, with Unix shells you can use single quotes (<code>&#39;</code>) and double quotes (<code>&quot;</code>) to group words together. The following alternatives are equivalent on Unix:</p>

<pre><code class="plaintext">&quot;two words&quot;
&#39;two words&#39;
two\ words</code></pre>

<p>In case of doubt, insert the following statement in front of your Perl program:</p>

<pre><code>print STDERR (join(&quot;|&quot;,@ARGV),&quot;\n&quot;);</code></pre>

<p>to verify how your CLI passes the arguments to the program.</p>

<h2 id="Undefined-subroutine-&amp;main::GetOptions-called"><a class="permalink" href="./Getopt::Long.html#Undefined-subroutine-&amp;main::GetOptions-called">#</a><a id="Undefined"></a><a id="Undefined-subroutine-main::GetOptions-called"></a>Undefined subroutine &amp;main::GetOptions called</h2>

<p>Are you running Windows, and did you write</p>

<pre><code>use GetOpt::Long;</code></pre>

<p>(note the capital &#39;O&#39;)?</p>

<h2 id="How-do-I-put-a-&quot;-?&quot;-option-into-a-Getopt::Long?"><a class="permalink" href="./Getopt::Long.html#How-do-I-put-a-%22-?%22-option-into-a-Getopt::Long?">#</a><a id="How"></a><a id="How-do-I-put-a---option-into-a-Getopt::Long"></a>How do I put a &quot;-?&quot; option into a Getopt::Long?</h2>

<p>You can only obtain this using an alias, and Getopt::Long of at least version 2.13.</p>

<pre><code>use Getopt::Long;
GetOptions (&quot;help|?&quot;);    # -help and -? will both set $opt_help</code></pre>

<p>Other characters that can&#39;t appear in Perl identifiers are also supported in aliases with Getopt::Long of at version 2.39. Note that the characters <code>!</code>, <code>|</code>, <code>+</code>, <code>=</code>, and <code>:</code> can only appear as the first (or only) character of an alias.</p>

<p>As of version 2.32 Getopt::Long provides auto-help, a quick and easy way to add the options --help and -? to your program, and handle them.</p>

<p>See <code>auto_help</code> in section <a href="./Getopt::Long.html#Configuring-Getopt%3A%3ALong">&quot;Configuring Getopt::Long&quot;</a>.</p>

<h1 id="AUTHOR"><a class="permalink" href="./Getopt::Long.html#AUTHOR">#</a>AUTHOR</h1>

<p>Johan Vromans &lt;jvromans@squirrel.nl&gt;</p>

<h1 id="COPYRIGHT-AND-DISCLAIMER"><a class="permalink" href="./Getopt::Long.html#COPYRIGHT-AND-DISCLAIMER">#</a><a id="COPYRIGHT"></a>COPYRIGHT AND DISCLAIMER</h1>

<p>This program is Copyright 1990,2015 by Johan Vromans. This program is free software; you can redistribute it and/or modify it under the terms of the Perl Artistic License or the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.</p>

<p>This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.</p>

<p>If you do not have a copy of the GNU General Public License write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.</p>


      </div>
      <div id="footer">
        <p>Perldoc Browser is maintained by Dan Book (<a href="https://metacpan.org/author/DBOOK">DBOOK</a>). Please contact him via the <a href="https://github.com/Grinnz/perldoc-browser/issues">GitHub issue tracker</a> or <a href="mailto:dbook@cpan.org">email</a> regarding any issues with the site itself, search, or rendering of documentation.</p>

<p>The Perl documentation is maintained by the Perl 5 Porters in the development of Perl. Please contact them via the <a href="https://github.com/Perl/perl5/issues">Perl issue tracker</a>, the <a href="https://lists.perl.org/list/perl5-porters.html">mailing list</a>, or <a href="https://kiwiirc.com/client/irc.perl.org/p5p">IRC</a> to report any issues with the contents or format of the documentation.</p>


      </div>
    </div>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.slim.min.js" integrity="sha512-/DXTXr6nQodMUiq+IUJYCt2PPOUjrHJ9wFrqpJ3XkgPNOZVfMok7cRw6CSxyCQxXn6ozlESsSh1/sMCTF1rL/g==" crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.1/umd/popper.min.js" integrity="sha512-ubuT8Z88WxezgSqf3RLuNi5lmjstiJcyezx34yIU2gAHonIi27Na7atqzUZCOoY4CExaoFumzOsFQ2Ch+I/HCw==" crossorigin="anonymous"></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js" integrity="sha384-B4gt1jrGC7Jh4AgTPSdUtOBvfO8shuf57BaghqFfPlYxofvL8/KUEfYiJOMMV+rV" crossorigin="anonymous"></script>
    <script src="../highlight.pack.js"></script>
    <script>hljs.highlightAll();</script>
  </body>
</html>
